package com.mr.dao.service;

import java.util.List;

import org.hibernate.classic.Session;
import org.springframework.transaction.annotation.Transactional;

import com.mr.dao.entity.BaseEntity;

/**
 * @author Alex
 */
public interface EntityService<T extends BaseEntity> extends Service {
	/**
	 * Load an object by id.
	 * @param id
	 * @return
	 */
	T load(Class<T> clazz, String id);

	/**
	 * Load an object by a regular property and its value.
	 * @param propertyName
	 * @param propertyValue
	 * @return
	 */
	T load(Class<T> clazz, String propertyName, Object propertyValue);

	/**
	 * Load a object by a set properties and their appropriate values.
	 * @param propertyNames
	 * @param propertyValues
	 * @return
	 */
	T load(Class<T> clazz, String[] propertyNames, Object[] propertyValues);

	/**
	 * Query all objects.
	 * @param orderProperties
	 * @return
	 */
	List<T> findAll(Class<T> clazz, String... orderProperties);

	/**
	 * Query objects by a property and its value.
	 * @param propertyName
	 * @param propertyValue
	 * @return
	 */
	List<T> find(Class<T> clazz, String propertyName, Object propertyValue);

	/**
	 * Query objects by a set properties and their appropriate values.
	 * @param propertyNames
	 * @param propertyValues
	 * @return
	 */
	List<T> find(Class<T> clazz, String[] propertyNames, Object[] propertyValues);

	/**
	 * Save or Update an object.
	 * @param o
	 */
	@Transactional(readOnly = false)
	void save(T o);

	/**
	 * Delete an object.
	 * @param o
	 */
	@Transactional(readOnly = false)
	void delete(T o);

	/**
	 * 
	 * @return
	 */
	Session getSession();
}
